package com.esm.sm800.sm800floating;

import com.esm.sm800.R;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

public class CustomSpinnerAdapter extends ArrayAdapter<String> {
    private int textColor;
    private int textSize;

    public CustomSpinnerAdapter(Context context, int resource, List<String> objects, int textColor, int textSize) {
        super(context, resource, objects);
        this.textColor = textColor;
        this.textSize = textSize;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View v = super.getView(position, convertView, parent);
        ((TextView) v).setTextColor(textColor);

        TextView textView;
        if (convertView == null) {
            textView = new TextView(getContext());
            textView.setLayoutParams(new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            textView.setGravity(Gravity.CENTER);
        } else {
            textView = (TextView) convertView;
        }

        textView.setText(getItem(position));
        textView.setTextSize(textSize);
        // 可以设置其他样式，如文字颜色、背景等

        return v;
    }
}
